* ===============================

* Title: Replication files for 'Analyzing International Organizations: How the Concepts We Use Affect the Answers We Get'
* Project: Re-analysis of Bernauer et al BJPS 2010
* Author: Charles B. Roger; Sam S. Rowan
* Contact: croger@ibei.org; sam.rowan@concordia.ca
* Date: 1 April 2021

* ===============================

**** Set working directory ****

* Set working directory to 'Roger and Rowan RIO 2021' on your machine


* ===============================
**** Load in Bernauer et al 2010 replication data, merge IO variables, and prepare for analysis ****
* ===============================

use "data/input/bkks_bjps.dta", clear

order cowcode year treaty, first
sort cowcode year treaty

** Original models
logit rightraty lopen polity2 faomemigo lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP t t2 t3,  cluster(cowcode)

** Replace some cow codes to merge data 
replace cow = 816 if cow == 818 /* Vietnam */ 
replace cow = 255 if cow == 260 & year > 1989 /* Germany */
replace cow = 316 if cow == 315 & year > 1992 /* Czechoslovakia/Czech Republic */
replace cow = 678 if cow == 679 & year < 1990 /* Recover the Yemen Arab Republic (678) for merging */

** Merge in new data, unit of analysis is ccode-treaty-years

rename cow ccode 
merge m:1 ccode year using "data/input/summaries_v3.dta"

replace ccode = 260 if ccode == 255 /* Reunite Germany for clustered standard errors to match BKKS */
replace ccode = 315 if ccode == 316 /* Reunite Czech Republic for clustered standard errors to match BKKS */
drop if ccode == 678 & treaty == .
drop if ccode == 679 & treaty == .
replace ccode = 679 if ccode == 678 /* Reunite Yemen for clustered standard errors to match BKKS */

keep if year >= 1950
keep if year <= 2000


* Sample composition
reg rightraty  faomemigo lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3,  cluster(ccode)
gen byte in_bkks = e(sample)

reg rightraty  cow_sum_member lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3,  cluster(ccode)
gen byte in_cow = e(sample)

reg rightraty  formals_sum_member lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3,  cluster(ccode)
gen byte in_formals = e(sample)

reg rightraty informals_sum_member lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3,  cluster(ccode)
gen byte in_informals = e(sample)

reg rightraty total_sum_member lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3,  cluster(ccode)
gen byte in_total = e(sample)

* Not run, to check sample composition
* tab in_bkks in_formals 
* tab in_bkks in_informals 

* ===============================
**** Replicate BKKS model 2 with new IO membership data
* ===============================

** Set new working directory for tables
cd "data/output"

* Replicate original table - table 3, model 2 (Polity with regional fixed effects)

logit rightraty faomemigo lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3 if in_bkks==1,  cluster(ccode)
outreg2 using bkks_table3_main, se tex append dec(3)  10pct e(r2_p, ll, N_clust) label /* 574,196 */

logit rightraty  formals_sum_member lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3 if in_bkks==1,  cluster(ccode)
outreg2 using  bkks_table3_main, se tex append dec(3)  10pct e(r2_p, ll, N_clust) label 

logit rightraty  informals_sum_member lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3 if in_bkks==1,  cluster(ccode)
outreg2 using  bkks_table3_main, se tex append dec(3)  10pct e(r2_p, ll, N_clust) label

logit rightraty  total_sum_member lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3 if in_bkks==1,  cluster(ccode)
outreg2 using  bkks_table3_main, se tex append dec(3)  10pct e(r2_p, ll, N_clust) label


* ===============================
**** Standardized effects for the different IO variables ****
* ===============================

** Create standardized versions of the key IO variables 

egen z_bkks = std(faomemigo)
egen z_formal = std(formals_sum_member)
egen z_informal = std(informals_sum_member)
egen z_total = std(total_sum_member)

** Re-run the models

qui logit rightraty z_bkks lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3 if in_bkks==1,  cluster(ccode)
est store bkks_bkks 

qui logit rightraty z_formal lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3 if in_bkks==1,  cluster(ccode)
est store bkks_formal 

qui logit rightraty z_informal lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3 if in_bkks==1,  cluster(ccode)
est store bkks_informal

qui logit rightraty z_total lopen polity2 lgrgdpc lgrgdpc2 lnso2pc threshold lagpercincome lagpercregion lnGDP africa NAM LAM eastasia westasia t t2 t3 if in_bkks==1,  cluster(ccode)
est store bkks_total

** Save the outputs to disk

esttab bkks_bkks bkks_formal bkks_informal bkks_total using bkks_esttab.csv, replace se nostar plain keep(z_bkks z_formal z_informal z_total)
 

* =============================== * =============================== * =============================== * ===============================
* END. 
* =============================== * =============================== * =============================== * ===============================

